﻿
@{
    Layout = null;
}

<style>
    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 45% !important;
    }
</style>
<div ng-controller="ReturnInfoController">
    <div class="container-fluid" ng-show="!selectProduct" id="AgentInfoUpdateMainViewPanel">
        <div class="row">
            <div class="col-md-12">
                <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal">
                    <!-- START panel-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading,'': isLoading }">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>退货申请信息</legend>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">订单号</label>
                                    <div class="col-sm-4">
                                        {{model.OrderNo}}
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">商品</label>
                                    <div class="col-sm-4">
                                        <label class="radio-inline c-radio">{{model.orderDetail.ProductName}}*{{item.orderDetail.ProductCount}}</label>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">商品总计价格</label>
                                    <div class="col-sm-4">
                                        {{model.ProductPrice}}
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset ng-show="model.RebatePrice>0">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">降拼活动返还余额</label>
                                    <div class="col-sm-4">
                                        {{model.RebatePrice}}
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">退货类型</label>
                                    <div class="col-sm-4">
                                        <label class="radio-inline c-radio">
                                            <input id="inlineradio1" type="radio" name="ReturnType" ng-model="model.ReturnType" value="0" checked="checked" >
                                            <span class="fa fa-circle"></span>退货
                                        </label>
                                        <label class="radio-inline c-radio">
                                            <input id="inlineradio2" type="radio" name="ReturnType" ng-model="model.ReturnType" value="1" >
                                            <span class="fa fa-circle"></span>换货
                                        </label>
                                    </div>
                                </div>
                            </fieldset>
                            @*<fieldset>
                                <div class="form-group" ng-show="model.ReturnType==0&&model.Satus<=1">
                                    <label class="col-sm-2 control-label"></label>
                                    <div class="col-sm-4">
                                        <label class="radio-inline c-radio">
                                            <input id="inlineradio1" type="radio" name="ReturnResult" ng-model="model.ReturnResult" value="0" checked="checked" ng-disabled="model.Satus>1">
                                            <span class="fa fa-circle"></span>全部退货
                                        </label>
                                        <label class="radio-inline c-radio">
                                            <input id="inlineradio2" type="radio" name="ReturnResult" ng-model="model.ReturnResult" value="1" ng-disabled="model.Satus>1">
                                            <span class="fa fa-circle"></span>部分退货
                                        </label>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset ng-show="model.ReturnType==0&&model.Satus>1">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"></label>
                                    <div class="col-sm-4">
                                        {{model.ReturnResultDes}}
                                    </div>
                                </div>
                            </fieldset>*@
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">原因</label>
                                    <div class="col-sm-4">
                                        <textarea name="Reason" readonly="readonly" rows="3" class="form-control" ng-model="model.Reason"></textarea>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">图片</label>
                                    <div class="col-sm-4">
                                        <a ng-repeat="img in model.ImgList" href="{{ImgHostUrl+img}}"  target="_blank"><img src="{{ImgHostUrl+img}}" /></a>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-sm-4">
                                        <select class="form-control" ng-model="model.Satus">
                                            <option value="0">待处理</option>
                                            <option value="1">客服处理中</option>
                                            <option value="3" ng-show="model.ReturnType==0">同意全部退货</option>
                                            <option value="5" ng-show="model.ReturnType==0">同意部分退货</option>
                                            <option value="4" ng-show="model.ReturnType==1" >同意换货</option>
                                            <option value="2">拒绝申请</option>
                                        </select>
                                    </div>
                                </div>
                            </fieldset>
                            @*<fieldset ng-show="model.Satus>1">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-sm-4">
                                        {{model.SatusDes}}
                                    </div>
                                </div>
                            </fieldset>*@
                            <fieldset ng-show="model.ReturnType==0">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">退款金额</label>
                                    <div class="col-sm-4">
                                        <input type="number" class="form-control" name="ReturnAmount" ng-model="model.ReturnAmount"/>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">客服备注</label>
                                    <div class="col-sm-4">
                                        <textarea name="Remark" placeholder="请输入备注" rows="3" class="form-control" ng-model="model.Remark"></textarea>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                        <div class="panel-footer text-right">
                            <button type="button" class="btn btn-warning" ng-click="cancel()">返回列表</button>
                            <button type="button" class="btn btn-primary" ng-click="save()">提交</button>
                            @*<button type="button" class="btn btn-primary" ng-show="model.ReturnType==0&&model.Satus<2" ng-click="confirm()">确认退货</button>
                            <button type="button" class="btn btn-primary" ng-show="model.ReturnType==1&&model.Satus<2" ng-click="change()">确认换货</button>
                            <button type="button" class="btn btn-primary" ng-show="model.Satus<2" ng-click="finish()">拒绝申请</button>*@
                        </div>
                    </div>
                    <!-- END panel-->
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    App.controller('ReturnInfoController', ["$scope", "$state", "$http", "$stateParams", "Notify", "$filter",
        function ($scope, $state, $http, $stateParams, Notify, $filter) {
            'use strict';
            $scope.isLoading = true;
            $scope.validateInput = function (name, type) {
                var input = $scope.formValidate[name];
                return (input.$dirty || $scope.submitted) && input.$error[type];
            };



            //数据初始化
            $scope.model = {};


            $http.post("/Order/GetReturnGoodsInfo", { id: $stateParams.id }).then(function (returnData) {
                $scope.isLoading = false;
                if (returnData.data.isSuccess) {
                    $scope.model = angular.copy(returnData.data.data);

                    if ($scope.model.ReturnType == 0 && $scope.model.Satus <= 1 && $scope.model.ReturnAmount <= 0)
                    {
                        $scope.model.ReturnAmount = $scope.model.ProductPrice;
                    }

                } else {
                    Notify.alert(returnData.data.msg, { status: 'warning' });
                    
                }
            });

            // 提交
            $scope.save = function () {
                $scope.submitted = true;
                $scope.isLoading = true;   

                if ($scope.formValidate.$valid) {
                    layer.confirm('确定提交吗？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        layer.closeAll('dialog');
                        $http.post("/Order/SaveReturnGoods", { model: $scope.model }).then(function (returnData) {
                            if (returnData.data.isSuccess) {
                                Notify.alert('操作成功!', { status: 'success' });
                                $state.go("app.returnGoods");
                            } else {
                                Notify.alert(returnData.data.msg, { status: 'warning' });
                                $scope.isLoading = false;
                            }
                        });
                    }, function () {

                    });
                    
                } else {
                    $scope.isLoading = false;
                }
            };

            $scope.finish = function () {
                $scope.submitted = true;

                layer.confirm('确定拒绝吗？确认后此申请状态将变为已完成，无法再修改', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    layer.closeAll('dialog');
                    $scope.model.Satus = 2;
                    $http.post("/Order/SaveReturnGoods", { model: $scope.model }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success' });
                            $state.go("app.returnGoods");
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning' });
                            $scope.isLoading = false;
                        }
                    });
                }, function () {

                });
            };

            $scope.change = function () {
                $scope.submitted = true;

                layer.confirm('确定换货吗？确认后此申请状态将变为已换货，无法再修改', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    layer.closeAll('dialog');
                    $scope.model.Satus = 2;
                    $http.post("/Order/SaveReturnGoods", { model: $scope.model }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success' });
                            $state.go("app.returnGoods");
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning' });
                            $scope.isLoading = false;
                        }
                    });
                }, function () {

                });
            };

            // 提交
            $scope.confirm = function () {
                $scope.submitted = true;
               
                layer.confirm('确认退货吗？确认后此申请状态将变为已退货，无法再修改', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    layer.closeAll('dialog');
                    $http.post("/Order/ConfirmReturnGoods", { model: $scope.model }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success' });
                            $state.go("app.returnGoods");
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning' });
                            $scope.isLoading = false;
                        }
                    });
                }, function () {

                });
            };

            //返回列表
            $scope.cancel = function () {
                $state.go("app.returnGoods");
            }
        }]);
</script>
